// 当前js文件的核心就是检测用户输入的create命令。然后接受具体的参数，将远端仓库下载下来

let axios = require('axios')
let inquirer = require('inquirer')
let ora = require('ora')

let fetchRepoList = async function () {
    let {data} = await axios.get('http://api.github.com/users/zcegg/repos')
    let repos = data.map(item => item.name)
    return repos
}
let fetchTagsList = async function () {
    let {data} = await axios.get('https://github.com/zcegg/create-nm/tags')
    let repos = data.map(item => item.name)
    return repos
}
let addLoading = function(fn) {
    let spinner = ora('拉去开始……')
    spinner.start()
    try {
        let res = fn()
        spinner.succeed('拉取成功')
        return res
    } catch (error) {
        console.log(error)
        spinner.fail('拉取失败')
    }
    
}

module.exports = async function (proname) {

    let repos = await addLoading(fetchRepoList)
    console.log(repos)
    let { temp } = await inquirer.prompt({
        type: 'list',
        name:'temp',
        message: '请选择目标仓库',
        choices: repos
    })
    console.log(temp)
    let tags = await addLoading(fetchTagsList)

    console.log(tags)



}

